package com.chinacache.maint.workorder.service;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.transaction.annotation.Transactional;

import com.chinacache.maint.commons.orm.hibernate.Page;
import com.chinacache.maint.commons.orm.hibernate.SimpleHibernateDao;
import com.chinacache.maint.workorder.entity.WorkOrder;

@Transactional
public class WorkOrderManager {
	private SimpleHibernateDao<WorkOrder, Integer> workOrderDao;

	@Required
	public void setSessionFactory(SessionFactory sessionFactory) {
		workOrderDao = new SimpleHibernateDao<WorkOrder, Integer>(
				sessionFactory, WorkOrder.class);
	}

	@Transactional(readOnly = true)
	public WorkOrder getWorkOrder(Integer id) {
		return workOrderDao.findById(id);
	}

	@Transactional(readOnly = true)
	public Page<WorkOrder> getAllWorkOrder(Page<WorkOrder> page) {
		return workOrderDao.findAll(page);
	}

	public void saveWorkOrder(WorkOrder workOrder) {
		workOrderDao.save(workOrder);
	}

	public void deleteWorkOrder(Integer id) {
		WorkOrder workOrder = workOrderDao.findById(id);
		workOrderDao.delete(workOrder);
	}

	public void updateWorkOrder(WorkOrder workOrder) {
		workOrderDao.update(workOrder);
	}

	@Transactional(readOnly = true)
	public List<WorkOrder> getAllWorkOrder() {
		return workOrderDao.findAll();
	}
}
